package com.example.puke;

import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private static final String TAG ="MainActivity" ;
    private String[] names={"ht0.png","ht1.png","ht3.png","ht4.png","ht5.png","ht6.png","ht7.png"
            ,"ht8.png","ht9.png","ht10.png","ht11.png","ht12.png"};
    private List<Bitmap> htList=new ArrayList();
    private MyLinearLayout mylin;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initDate();
        initView();
    }

    /**
     * 初始化控件
     */
    private void initView() {
        mylin= (MyLinearLayout) findViewById(R.id.mylin);
        Bitmap bitmap=htList.get(0);
        int width=bitmap.getWidth();//扑克宽度
        int height=bitmap.getHeight();//扑克高度
        mylin.setPuKeWandH(width,height,htList);
        mylin.setStar(R.drawable.star);
    }

    /**
     * 初始化数据
     */
    private void initDate() {
        addPuKe();
    }

    /**
     * 添加扑克牌进入数组
     */
    private void addPuKe() {
        AssetManager assetManager = getAssets();
        InputStream is = null;
        for (int i=0;i<13;i++) {
            try {
                is = assetManager.open("ht"+i+".png");
                Bitmap bitmap = BitmapFactory.decodeStream(is);
                htList.add(bitmap);
                is.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
